package com.wyman.context.support;

import com.wyman.beans.BeanException;
import com.wyman.beans.factory.config.BeanPostProcessor;
import com.wyman.context.ApplicationContext;
import com.wyman.context.ApplicationContextAware;


/**
 * @Author 李伟民
 * @Description
 * @DateTime 2024/12/14 01:04
 */
public class ApplicationContextAwareProcessor implements BeanPostProcessor {


    private final ApplicationContext applicationContext;

    public ApplicationContextAwareProcessor(ApplicationContext applicationContext){
            this.applicationContext = applicationContext;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeanException {

        if(bean instanceof ApplicationContextAware){
            ((ApplicationContextAware)bean).setApplicationContext(applicationContext);
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeanException {
        return bean;
    }
}
